const { sumUnknownTokens } = require('../helper/unknownTokens')
async function staking(api) {
  const data = await api.fetchList({ lengthAbi: 'uint256:poolLength', itemAbi: 'function poolInfo(uint256) view returns ( address want, uint256, uint256, uint256, address strat)', target: '0x55410D946DFab292196462ca9BE9f3E4E4F337Dd' })
  const tokensAndOwners = data.map(pool => [pool.want, pool.strat])
  return api.sumTokens({ tokensAndOwners, blacklistedTokens: ['0xe837d51f5937c450a6d28280ab73b2602cde7735'] })
}


async function tvl(api) {
  const v2Vaults = [
    "0xD0CEe0BF1fC137777a8a53f4C99000B5A2269c31",
    "0xD0CEd4bbDdeC0e97fFE579e2f162aecB9383ac6D",
    "0xD0CEd179290beB24c1b42C73d701f199F2989D27",
    "0xD0CEA25545eC1440ffE82dC860cA348cd1178792",
    "0xD0CE91F507cE4a51442B6022E8c85aC287bcd048",
    "0xD0CE39E2750e4aCDc63760e642Ba7a0B341b842E",
    "0xD0CEb6DB9fF7E4B45F450a344B1b8c2512D79DB8",
    "0xD0CE4a27FD544416D22aC4DE50384111B26e7902",
    "0xD0CEf44C1F9F123D45A6bCD6ECcC8436209Da066",
    "0xD0CEfDe05Bf55CA1693476A5B8B05F5494A6dBC3",
    "0xD0CEb8DaE2A8D390AeC07cD13bbdfCF99bcEF0b1",
    "0xD0CEd165609Aa0eB471ee93F60a47c4f302F313c",
    "0xD0CE7c79A28CB2ae6332fD4fdB18291FF32E2872",
    "0xD0CEfEaa4C746912C3BcF002992F2aFF8364CE1A",
    "0xD0CE0D5413414E8c75289D9Fe81A297234F970c9",
    "0xD0CED5594c70e16550a33a5ae52E70596D2ee267",
    "0xD0CEa1e6F5f343961f4A869af0951123aa39092d",
    "0xD0CEa5d14B0eDAF5779f64D7d6F3617DE09fFBa5",
    "0xD0CE0018cFBa3B27574486dd2328b213e04b417f",
    "0xD0CEa8507f33BB4C9FF4885EAcB535cB41C2dc67",
    "0xD0CEb09DB35b1F5a8e5F0572668Eb1b212F1A343",
    "0xD0CEb6698958089f9609be9DDC1b9559967DA606",
    "0xD0CEcf6F187eD18653Bc491570720Fb2eaffa6Ef",
    "0xD0CEb528e9313737DC283b072C5338795C163E93",
    "0xD0CEc9Db398BA15c91F98b4524ab80682503339E",
    "0xD0CEcD6e1804810338024C41EAB9872A1A723255",
    "0xD0CEdd809Dc5e17ddf846453309c41d727605a9C",
    "0xD0CEa2e0ddC11Fa357f3dEe3e67d0dD842C30c05",
    "0xD0CEb87a7139692AeCBc8FeC8bCDCCcDa23De69E",
    "0xD0CEa5ec555B71abE601d76208cD79D08ED9A143",
    "0xD0CEc030fBf50FF3419377951C9503A5159BF411",
    "0xD0CEeF6828763351155b793E9F2Cd9C3fE7440A6",
    "0xD0CEc151AD35b64c4Fb42C0Df7cDe0f349D0fa43",
    "0xD0CEf749f85FBD925cFb0B136c92C710e90F5Fe1",
    "0xD0CEc6C537780829089F387Aa6C21c0823186fA7",
    "0xD0CEde5b349Dd101cff2f063514595e802feE683",
    "0xD0CEb3c3943Ad5252d9A91e99469c2079C38ECC5",
    "0xD0CEf1D7E519afbb66f57b3B3D5C39Eee7405090",
    "0xD0CEa9e111d3c7947bcA7510b9Eef3869aFcf8b4",
    "0xD0CEb6740E31d5Ede1961963D6160e155C23d2B3",
    "0xD0CEcba58C5e83bf6506AA471E4f4740846c8C31",
    "0xD0CEbe7B1550f474f728C553d9508e14aC5fFb9F",
    "0xD0CEc104d1798dbFc943Eb41349099C71F6C47c3",
    "0xD0CEf92C9cCFFe5640F62F11a48ABC5948fee98D",
    "0xD0CEa14953480125Cff993BD63f6B6659693E73B",
    "0xD0CEdc18dBe9c81A533E971917772aF4192bBF00",
    "0xD0CEd0bb37DeFe6d2c7B8d9BdfA1529C850DD131",
    "0xD0CEa1D43C233a1758f4689302cFE243C1da63E0",
    "0xD0CEd8680d7676D278c13f6603363011F44670A2",
    "0xD0CEdffAA4d05f3fe91486ce17d2e4C16b02C30C",
    "0xD0CEa57e2A91a40447B6B64f9C039c4f990E7878",
    "0xD0CEceCAA302f707DB2100Df9379C8D8Bb179D80",
    "0xD0CEeaE6181C50b32fE83fBBde2Cd7DcCA3023aa",
    "0xD0CE11034ebf731162Bc50c05Ba57809791d8b7d",
    "0xD0CE12b874aa0Da96563e9096Bc90e950859b66e",
    "0xD0CE7d29ac012702A41F410b7ceaa7Be104BBCe8",
    "0xD0CE387Bb8a117F51Ad44889d99A1026634d6981",
    "0xD0CEa7C3B535C0484D41026819d1FAF8729041A2",
    "0xD0CE57584e2cA1Acad2Eae12a71EecFAcE7Fb244",
    "0xD0CEb625BfFCBc08F66917a56D015f23A07196F6",
    "0xD0CE1E3d9c34647a4Ad7Cd7d2A9A202243393F47",
    "0xD0CEdc5104602c085b695b980c9912951d8FffDb",
    "0xD0CEEF5c4A337b9E3F680e682B1Ea0E611b52561",
    "0xD0CEE30000f220872F5Fdd38CE0aF5294B76FBaa",
    "0xD0CEE9272a47079d0298Fd353E89f76D0d907051",
    "0xD0CE871496b859b57EFc425B7AbC97E4C64e5d34",
    "0xD0CE955E9CB63a2477a4046430A04e4A04aB29b7",
    "0xD0CE42947fe733c4F6f99Ba1AD042B037b30dfc9",
    "0xD0CE475D00Af87c60a767a0017421D4A32a8FfC5",
    "0xD0CE2b627AB7bef9ca53F489976e82B3D8D1C5A4",
    "0xD0CE59764527b6Ff93b268D93E34Bc32c08c9ee2",
    "0xD0CEafceb360bdcC65D4Fe0E0a44e2656cF75184",
    "0xD0CEad415a3DC034f967ABE4345d6C832a97c866",
    "0xD0CE6E3b75371e244d6Dd19e0a3f9B4A83bAEd08",
    "0xD0CEcBfbFE266D98b16112073037084126Efd267",
    "0xD0CE3013eF6EedF2A7E7a03d9F1421Cff258f4C7",
    "0xD0CE66Be3c69d5CE92A6F5A1559d1733891b8c34",
    "0xD0CE399c94Af9cDDbBD70410D424300a6E3c4473",
    "0xD0CEb06277FdE9F3aE4FAcD317f3B0b1d8E6f0AA",
    "0xD0CE92AA105D79E7aC59e1D14dEf15eB256Feec2",
    "0xD0CE668B95F82a376D153bF0de2E87bfD271b871"
  ]

  const v1Vaults = [
    "0x16205528a8f7510f4421009a7654835b541bb1b9",
    "0x705dA3639Ebb5F8255a520d6e9d016F5a3eBce8D",
    "0xD0CEc79567576B0f5b4b8957B0B82f1f88d4C7d1",
    "0xD0CEa90a27574Ab7B7B0B9B12d3BDF98ad4be5A2",
    "0xD0CEc23fE3d1DF4D5aB71f147934bCB1Aa34521B",
    "0x7cFAc15c404D1798d08888Af60E386E384636b8D",
    "0x1eD05e6d9a66c4d8d789e8198F0282C261807F8b",
    "0xD0CEe98675F17f4CaBE4f42f481465F87df3B8BD",
    "0xD0CE645C728B70d29014d8A882029144De3d37FB",
    "0xD0CEBBC82Ee17a5c52627935A028a4aFB0De799c",
    "0xD0CEEC3233Ea1Aba3EC055660AbEC6e8b99e1c1c",
    "0xD0CE6Aea3e4871F88e428a4651835FAfE35C7f43",
    "0xD0CEf575f56092d92fC56c2F6B9D62D45E7DA73F"
  ]
  const vaults = v1Vaults.concat(v2Vaults)
  const tokens = await api.multiCall({ abi: 'address:STAKED_TOKEN', calls: vaults, permitFailure: true })
  const bals = await api.multiCall({ abi: 'uint256:totalStake', calls: vaults, permitFailure: true })
  tokens.forEach((token, i) => {
    if (!token || !bals[i]) return;
    api.add(token, bals[i])
  })
  return api.getBalances()
}

module.exports = {
  bsc: {
    tvl, staking,
  },
};
